<?php

/**
 * This is the model class for table "share".
 *
 * The followings are the available columns in table 'share':
 * @property integer $share_ID
 * @property integer $sharer_ID
 * @property string $shared_on
 * @property string $url
 * @property string $type
 * @property string $title
 *
 * The followings are the available model relations:
 * @property User $sharer
 */
class Share extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return Share the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'share';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('share_ID, sharer_ID', 'required'),
			array('share_ID, sharer_ID', 'numerical', 'integerOnly'=>true),
			array('url', 'length', 'max'=>2048),
			array('type', 'length', 'max'=>45),
			array('title', 'length', 'max'=>100),
			array('shared_on', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('share_ID, sharer_ID, shared_on, url, type, title', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'sharer' => array(self::BELONGS_TO, 'User', 'sharer_ID'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'share_ID' => 'Share',
			'sharer_ID' => 'Sharer',
			'shared_on' => 'Shared On',
			'url' => 'Url',
			'type' => 'Type',
			'title' => 'Title',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('share_ID',$this->share_ID);
		$criteria->compare('sharer_ID',$this->sharer_ID);
		$criteria->compare('shared_on',$this->shared_on,true);
		$criteria->compare('url',$this->url,true);
		$criteria->compare('type',$this->type,true);
		$criteria->compare('title',$this->title,true);

		return new CActiveDataProvider(get_class($this), array(
			'criteria'=>$criteria,
		));
	}
}